#include "napi/native_api.h"
#include <cstdint>
#include <cstring>
#include <filemanagement/file_uri/oh_file_uri.h>
#include <js_native_api_types.h>
#include <node_api.h>

static napi_value CreateMetadata(napi_env env, const int64_t duration, const int64_t bitrate, napi_value metadata,
                                 int bitsPerRawSample, int sampleRate, int channels, napi_value cover) {
    napi_value object;
    napi_create_object(env, &object);

    // 1. 设置duration属性
    napi_value durationKey, durationValue;
    napi_create_string_utf8(env, "duration", NAPI_AUTO_LENGTH, &durationKey);
    napi_create_int64(env, duration, &durationValue);
    napi_set_property(env, object, durationKey, durationValue);

    // 2. 设置bitrate属性
    napi_value bitrateKey, bitrateValue;
    napi_create_string_utf8(env, "bitrate", NAPI_AUTO_LENGTH, &bitrateKey);
    napi_create_int64(env, bitrate, &bitrateValue);
    napi_set_property(env, object, bitrateKey, bitrateValue);

    // 3. 设置metadata属性
    napi_value metadataKey;
    napi_create_string_utf8(env, "metadata", NAPI_AUTO_LENGTH, &metadataKey);
    napi_set_property(env, object, metadataKey, metadata);

    // 4. 设置bitsPerRawSample属性
    napi_value bitsPerRawSampleKey, bitsPerRawSampleValue;
    napi_create_string_utf8(env, "bitsPerRawSample", NAPI_AUTO_LENGTH, &bitsPerRawSampleKey);
    napi_create_int32(env, bitsPerRawSample, &bitsPerRawSampleValue);
    napi_set_property(env, object, bitsPerRawSampleKey, bitsPerRawSampleValue);

    // 5. 设置sampleRate属性
    napi_value sampleRateKey, sampleRateValue;
    napi_create_string_utf8(env, "sampleRate", NAPI_AUTO_LENGTH, &sampleRateKey);
    napi_create_int32(env, sampleRate, &sampleRateValue);
    napi_set_property(env, object, sampleRateKey, sampleRateValue);

    // 6. 设置channels属性
    napi_value channelsKey, channelsValue;
    napi_create_string_utf8(env, "channels", NAPI_AUTO_LENGTH, &channelsKey);
    napi_create_int32(env, channels, &channelsValue);
    napi_set_property(env, object, channelsKey, channelsValue);

    // 7. 设置cover属性
    napi_value coverKey;
    napi_create_string_utf8(env, "cover", NAPI_AUTO_LENGTH, &coverKey);
    napi_set_property(env, object, coverKey, cover);

    return object;
}